package com.lonbon.threecameramaster.test;


import static com.lonbon.threecameramaster.test.ApiUtils.setPowerOnTime;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.lonbon.threecameramaster.R;


/**
 * 定时开机
 */
public class TimerOpenActivity extends AppCompatActivity {

    private DatePicker datePicker;
    private TimePicker timePicker;
    private Button btnClose;

    private String date,time;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timer_close_activity);

        datePicker = findViewById(R.id.date_picker);
        int year = 2023;
        int month = 11;
        int dayOfMonth = 28;
        datePicker.init(year, month, dayOfMonth, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                // 处理选择的日期
                date = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;
                Toast.makeText(TimerOpenActivity.this, "选择的日期是：" + date, Toast.LENGTH_SHORT).show();
            }
        });

        timePicker = findViewById(R.id.time_picker);
        timePicker.setIs24HourView(true);
        timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                // 处理选择的时间
                time = hourOfDay + ":" +  minute +":00";
                Toast.makeText(TimerOpenActivity.this, "选择的时间是：" + time, Toast.LENGTH_SHORT).show();
            }
        });

        btnClose = findViewById(R.id.btn_close);
        btnClose.setText("设置定时开机");
        btnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //
                Log.d("TimerOpenActivity","selectTime="+ date + " " + time);
//                ApiUtils.setPoweron(TimerOpenActivity.this,true,date+" "+time);
//                ApiUtils.shutDown(getApplicationContext());
                setPowerOnTime(System.currentTimeMillis() + 30000);

            }
        });
    }
}
